2 4 6 8 10
The loop control variable (the counter) C
starts at 2,
then the program counts upward by twos until it reaches the ending value of 10.
Here is the general form of the FOR
(again):
FOR counter = startingValue TO endingValue STEP stepSize loopBody NEXT counter
Here are some rules about how the FOR
statement works:
As usual, these rules look a lot worse than they really are. A few examples should help. Here is a program that lists out odd numbers. It starts at 1, then goes to 3, then to 5, and so on. The problem is deciding where it stops.
FOR ODD = 1 TO 5 STEP 2 PRINT ODD; NEXT ODD ' END
What will the program print out?